//
//  RecommendTableViewCell.m
//  艾听歌
//
//  Created by dllo on 16/5/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RecommendTableViewCell.h"
#import "HotCViewcell.h"

@interface RecommendTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *hotCollectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *hotFlowLayout;

@end


@implementation RecommendTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createHotCollectionView];
    }
    return self;
}
- (void)createHotCollectionView
{
    self.hotFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.hotFlowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 3 - 10, (self.contentView.frame.size.height / 2 - 10));
    self.hotFlowLayout.minimumInteritemSpacing = 0.5;
  self.hotFlowLayout.sectionInset = UIEdgeInsetsMake(4, 4, 4, 4);
    self.hotCollectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:self.hotFlowLayout];
    self.hotCollectionView.delegate = self;
    self.hotCollectionView.dataSource = self;
    [self.contentView addSubview:self.hotCollectionView];
//    self.hotCollectionView.backgroundColor = [UIColor clearColor];
    self.hotCollectionView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9C9C9C);
    self.hotCollectionView.bounces = NO;

    [self.hotCollectionView registerClass:[HotCViewcell class] forCellWithReuseIdentifier:@"hotcell"];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.hotCollectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.hotFlowLayout.itemSize = CGSizeMake((self.contentView.frame.size.width) / 3 - 10, (self.contentView.frame.size.height) / 2 - 10);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.data.count;
//    return 6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HotCViewcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hotcell" forIndexPath:indexPath];
    cell.NewCellModel = [self.data objectAtIndex:indexPath.row];
    
    return cell;
}


-(void)setNewCellModel:(MusicModel *)NewCellModel{
    
    _NewCellModel = NewCellModel;
    self.data = [NSMutableArray arrayWithArray:_NewCellModel.data];
    
    [self.hotCollectionView reloadData];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
